<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
<title>借款申请</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="/resources/css/base.css" rel="stylesheet"
	type="text/css" />
<link href="/resources/js/miniui/themes/default/miniui.css"
	rel="stylesheet" type="text/css" />
<script src="/resources/js/jquery-1.6.2.min.js"
	type="text/javascript"></script>
<script src="/resources/js/miniui/miniui.js"
	type="text/javascript"></script>
<style type="text/css">
#editWindow {top: 50px !important;left:250px!important}
</style>
</head>

<body>
	<div style="padding-top: 5px; padding-bottom: 5px;    width: 95%;">
		<a class="mini-button"
			img="/resources/js/miniui/themes/icons/add.gif"
			onclick="load4add()">增加</a> 
		<a class="mini-button"
			img="/resources/js/miniui/themes/icons/edit.gif"
			onclick="editRow()">修改</a> 
		<a class="mini-button"
			img="/resources/js/miniui/themes/icons/remove.gif"
			onclick="delRow()">删除</a>
		<div style="float: right;">
			<span>姓名：</span><input type="text" id="name" /> 
			<span>手机号码：</span><input type="text" id="phone" /> 
			<input type="button" value="查找" onclick="search()" />
		</div>
	</div>
	<!-- <fieldset style="border: solid 1px #aaa; padding: 3px;width: 94%;margin-bottom: 5px;">
		<legend>搜索</legend>
		<div style="padding-top: 5px; padding-bottom: 5px; width: 100%;">
			<span>姓名：</span><input type="text" id="name" /> 
			<span>手机号码：</span><input id="phone" type="text" /> 
			<span>产品类型：</span><input id="type" class="mini-combobox"
						valueField="id" textField="text" valueFromSelect="true"
						url="/apply/getType" />
			<span>状态：</span><input id="status" class="mini-combobox"
						valueField="id" textField="text" valueFromSelect="true"
						url="/apply/getStatus" />
			<input type="button" value="查找" onclick="search()" />
		</div>
	</fieldset> -->

	<div id="mini-datagrid" class="mini-datagrid"
		style="width: 95%; height: 400px;"
		url="/apply/selectApplyListByPage" pageSize="20" idField="id"
		allowResize="true">

		<div property="columns">
			<div type="indexcolumn">序号</div>
			<div type="checkcolumn">选择</div>
			<div field="name">姓名</div>
			<div field="phone">手机号码</div>
			<div field="amount">借款金额(元)</div>
			<div field="recommend">推荐人</div>
			<div field="time">借款时间(月)</div>
			<div field="address">联系地址</div>
			<div field="type" renderer="typeRen">产品类型</div>
			<div field="status" renderer="statudRen">审核状态</div>
			<!-- <div field="isSupplier" renderer="supplierRen">是否为供应商</div> -->
		</div>
	</div>


	<div id="editWindow" class="mini-window" title="借款窗口"
		style="width: 350px;" showModal="true" allowResize="true"
		allowDrag="true">
		<div id="editform" class="form">
			<input class="mini-hidden" name="id" value="0" />
			<table style="width: 100%;">
				<tr>
					<td style="width: 30%;text-align: right;">姓名：</td>
					<td style="width: 70%;text-align: left;"><input name="name"
						class="mini-textbox" maxLength=200 /></td>
				</tr>
				<tr>
					<td style="width: 30%;text-align: right;">手机号码：</td>
					<td style="width: 70%;text-align: left;"><input name="phone"
						class="mini-textbox" maxLength=200 /></td>
				</tr>
				<tr>
					<td style="width: 30%;text-align: right;">借款金额：</td>
					<td style="width: 70%;text-align: left;"><input name="amount"
						class="mini-textbox" maxLength=200 /></td></td>
				</tr>
				<tr>
					<td style="width: 30%;text-align: right;">产品类型：</td>
					<td style="width: 70%;text-align: left;"><input name="type"
						class="mini-textbox" maxLength=10 /></td></td>
				</tr><!--  -->
				<tr>
					<td style="width: 30%;text-align: right;">推荐人：</td>
					<td style="width: 70%;text-align: left;"><input name="recommend"
						class="mini-textbox" maxLength=200 /></td></td>
				</tr>
				<tr>
					<td style="width: 30%;text-align: right;">借款时间(天)：</td>
					<td style="width: 70%;text-align: left;"><input name="time"
						class="mini-textbox" maxLength=10 /></td></td>
				</tr>
				<tr>
					<td style="width: 30%;text-align: right;">联系地址：</td>
					<td style="width: 70%;text-align: left;"><input name="address"
						class="mini-textbox" maxLength=200 /></td></td>
				</tr>
				<tr>
					<td style="width: 30%;text-align: right;">借款状态：</td>
					<td style="width: 70%;text-align: left;"><input name="status"
						class="mini-combobox" valueField="id" textField="text"
						valueFromSelect="true" url="/apply/getStatus"/></td>
				</tr><!-- -->
				<tr>
					<td
						style="text-align: center; padding-top: 5px; padding-right: 20px;"
						colspan="6"><a class="mini-button"
						img="/resources/js/miniui/themes/icons/save.gif"
						onclick="saveRow()">保存</a> <a class="mini-button"
						img="/resources/js/miniui/themes/icons/cancel.gif"
						onclick="cancelRow()">取消</a></td>
				</tr>

			</table>
		</div>
	</div>
<input type="hidden" value="${type}" id="reqType"/>
<input type="hidden" value="${status}" id="reqStatus"/>
</body>
<script type="text/javascript">
	var reqType = $("#reqType").val();
	var reqStatus = $("#reqStatus").val();

	mini.parse();
	var datagrid = mini.get("mini-datagrid");
	var editWindow = mini.get("editWindow");
	var form = new mini.Form("editform");
	var actionType = "insertApply";
	datagrid.load({ 
		type:reqType,
		status:reqStatus
	});

	function load4add() {
		actionType = "insertApply";
		editWindow.show();
		form.clear();
	}

	function saveRow() {
		var json = form.getData();
		console.log(json.id);
		if (json.id == 'undefined' || json.id == '') {
			json.id = 0;
		}
		console.log(json);
		$.ajax({
			url : "/apply/" + actionType,
			data : json,
			type : "post",
			success : function(text) {
				editWindow.hide();
				datagrid.reload();
			},
			error : function(jqXHR, textStatus, errorThrown) {
				alert(jqXHR.responseText);
			}
		});

	}

	function cancelRow() {
		datagrid.reload();
		editWindow.hide();
	}

	function editRow() {

		var node = datagrid.getSelected();
		if (node) {
			actionType = "updateApply";
			editWindow.show();
			form.clear();
			form.setData(node);
		} else {
			mini.alert("请选择一条!");
		}
	}

	function delRow() {

		var node = datagrid.getSelected();
		if (node) {
			mini.confirm("确定删除！", "提示", function(retCode) {
				console.log(retCode);
				if (retCode == 'ok') {
					// dosomething 删除
					$.ajax({
						url : "/apply/deleteApply",
						data : {
							id : node.id
						},
						type : "post",
						success : function(text) {
							editWindow.hide();
							datagrid.reload();
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert(jqXHR.responseText);
						}
					});

				}
			})
		} else {
			mini.alert("请选择一条!");
		}
	}
	
	function search(){
		datagrid.load({ 
				name: $('#name').val(),
				phone:$('#phone').val(),
				type:mini.get("#type").getValue(),
				status:mini.get("#status").getValue()
			});
	}
	
	function statudRen(e) {
	   var status = [{ id: 1, text: '已申请' }, { id: 2, text: '已通过'}, { id: 3, text: '未通过'} ];
	   for (var i = 0, l = status.length; i < l; i++) {
         var g = status[i];
         if (g.id == e.value)
        	 return g.text
       }
	   return "-";
	}
	
	function typeRen(e){
		var type = [{ id: 1, text: '商抵贷' }, { id: 2, text: '赎楼贷(个人)'}, { id: 3, text: '赎楼贷(企业)'},
		              { id: 4, text: '尾款贷' }, { id: 5, text: '房易贷'}, { id: 6, text: '装修贷'} ];
		 for (var i = 0, l = type.length; i < l; i++) {
	         var g = type[i];
	         if (g.id == e.value)
	        	 return g.text
	     }
		 return "-";
	}
	
	function supplierRen(e){
		var supplier = [{ id: 'N', text: '否' }, { id: 'Y', text: '是'} ];
		for (var i = 0, l = supplier.length; i < l; i++) {
        	var g = supplier[i];
        	if (g.id == e.value)
        		return g.text
    	}
		return "-";
	}
</script>

</html>
